#include "ip_maker.h"
char * ip_maker(uint16_t data_len,uint16_t id,char * sip,char * dip){
    struct iphdr ip_head ={
        .version = 4,
        .ihl = 5,
        .tos=0,
        .tot_len = htons(sizeof(struct iphdr)+data_len),
        .id = htons(id),
        .frag_off = htons(0),
        .ttl = 64,
        .protocol = 0x11,
        .check = htons(0),
    };
    memcpy(&ip_head.saddr,sip,4);
    memcpy(&ip_head.daddr,dip,4);

    char * ip_hd_buf = malloc(sizeof(struct iphdr));
    memcpy(ip_hd_buf,&ip_head,sizeof(struct iphdr));

    uint16_t chksum = pck_checksum(ip_hd_buf,sizeof(struct iphdr));
    memcpy(&ip_head.check,&chksum,2);
    memcpy(ip_hd_buf,&ip_head,sizeof(struct iphdr));
    return ip_hd_buf;

}